home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: 11 Jan 1996 15:35:08 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan11103508@g7240065.bridge.bst.bls.com>
- References: <4d1g3k$o09@solaris.cc.vt.edu> <4d34p7$kj9@tahko.lpr.carel.fi>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: aril@cmt.lpr.mail.carel.fi's message of Thu, 11 Jan 1996 13:47:01
- GMT
-
- In article <4d34p7$kj9@tahko.lpr.carel.fi> aril@cmt.lpr.mail.carel.fi (Ari Lukumies) writes:
-
- : Ashutosh Gokhale <ashutosh> wrote:
- :> Suppose I have an array A[][][] which I declare as
- :> double ***A and then assign memory to it using new operator.
- :> Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
- :> entries of A using
- :> for(i=1; i<50; i++)
- :> {
- :> for(j=1; j<60; j++)
- :> {
- :> for(k=1; k<70; k++)
- :> {
- :> A[i][j][k] = <some expression>;
- :> }
- :> }
- :> }
- :> But the above way is surely the most time-INEFFICIENT way.
- :> Can someone suggest me the MOST time efficient way of indexing through A[][][]?
-
- : Try this:
-
- : double *p = A;
- : for (i = 0; i < 50*60*70; i++)
- : *p++ = <some expression>;
-
- : BTW, array indexes in C/C++ begin at 0, _not_ at 1.
-
- The original poster send A was of type double***
- If the allocation was done like:
-
- A = new double**[50];
- for (int i = 0; i < 50; i++) {
- A[i] = new double*[60];
- for (int j = 0; j < 60; j++) {
- A[i][j] = new double[70];
- }
- }
-
- Then
- double* p = A;
- is not sufficient. And without a cast it wouldn't work.
-
- Regards
-
- -A
-
- --
- | A.Champion |
-